package com.lefevre.cms.web.action.common;


import com.lefevre.cms.bean.theme.Layout;
import com.lefevre.cms.service.theme.ThemeService;
import com.lefevre.cms.web.action.AccessDeviceUtil;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 站点栏目
 */
@Controller
public class ColumnAction {
    @Resource
    ThemeService themeService;
    @Resource
    AccessDeviceUtil accessDeviceUtil;

    @RequestMapping(value = "/column/{columnId}", method = RequestMethod.GET)
    public String execute(ModelMap model, @PathVariable Integer columnId,
                          HttpServletRequest request, HttpServletResponse response) throws Exception {
        //当前模板使用的目录
        String dirName = themeService.findTemplateDir_cache();
        if (columnId != null && columnId > 0) {

            Layout layout = themeService.findLayoutByReferenceCode_cache(dirName, 7, "column_" + columnId);
            if (layout != null) {


                return "/templates/" + dirName + "/" + accessDeviceUtil.accessDevices(request) + "/public/column_" + columnId;
            }
        }

        return null;
    }
}
